import 'package:slk/util/common.dart';
import 'package:slk/util/config.dart';
import 'package:slk/util/url.dart';

/**
 * 登录
 */
void slk_login(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    'email': data['email'],
    'password': data['password'],
    'userName': data['email'],
    'verCode': "",
    'verCodeType': 5,
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('login'),
    'method': 'POST',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 调用百度接口获取定位信息
 */
void slk_location(Map data, Function(String)? cb) {
  LOGI('location param $data');

  Map loginData = {
    'ak': dq_configInfo()['ak'],
    'output': 'json',
    'location': data['location'], // '32.086934,118.876353',
    'coordtype': 'wgs84ll',
    'language': 'zh-CN',
    'language_auto': '0',
    'extensions_poi': '0',
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('baiduLocation'),
    'method': 'GET',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 根据字典类型获取字典列表
 */
void slk_getDictItemsPageList(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    ...data,
    // 'DictType': data['DictType'],
    'Page': 1,
    'PageSize': 100,
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('dictitempagelist'),
    'method': 'GET',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 根据字典类型获取字典列表
 */
void slk_getDictItemsForType(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    ...data,
    // 'DictType': data['DictType'],
    'Page': 1,
    'PageSize': 100,
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('dictitems'),
    'method': 'GET',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 根据字典类型获取字典列表
 */
void slk_getDictTypes(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    ...data,
    // 'DictType': data['DictType'],
    'Page': 1,
    'PageSize': 100,
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('dicttypes'),
    'method': 'GET',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 新增销售拜访
 * @param params 
    RecId: 'string',
    RecNum: 0,
    BizCode: 'string',
    PlanId: 'string',
    CustomerId: 'string',
    Note: 'string',
 * @returns
 */
void slk_addSalesVisit(Map data, Function(String)? cb) {
  // Map c = {
  //   'Customer': "的撒大",
  //   'CustomerType': "经销商",
  //   'FllowStatus': "开发拜访",
  //   'Note': "大厦",
  //   'SalesId': "",
  //   'VisitContent': "的撒大",
  //   'VisitDate': "2024-01-26 19:37:49",
  //   'VisitFeedback': "大撒大撒",
  //   'VisitTyte': "陌生拜访",
  //   'VisitWay': "上门拜访"
  // };
  LOGI('param $data');

  var loginData = {
    ...data,
    // 'Customer': data['Customer'],
    // 'CustomerType': data['CustomerType'],
    // 'FllowStatus': data['FllowStatus'],
    // 'Note': data['Note'],
    // 'SalesId': data['SalesId'],
    // 'VisitContent': data['VisitContent'],
    // 'VisitDate': data['VisitDate'],
    // 'VisitFeedback': data['VisitFeedback'],
    // 'VisitTyte': data['VisitTyte'],
    // 'VisitWay': data['VisitWay'],
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('addSalesVisit'),
    'method': 'POST',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 查询销售拜访记录
 */
void slk_getSalesVisitPageList(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    ...data,
    // 'Page': data['Page'],
    // 'PageSize': data['PageSize'],
    // 'DateRange': data['DateRange'],
    // 'SalesId': data['SalesId'],

    //
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('getSalesVisit'),
    'method': 'POST',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 添加签到记录
 */
void slk_addAttendance(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    ...data,
    // "RecId": 'string',
    // "RecNum": 0,
    // "AttendanceName": data['AttendanceName'],
    // "AttendanceId": data['AttendanceId'],
    // "AttendancePlace": data['AttendancePlace'],
    // "AttendanceTime": data['AttendanceTime'],
    // "Note": data['Note'],
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('attendance'),
    'method': 'POST',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 * 获取签到记录
 */
void slk_getAttendance(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    ...data,
    // "RecId": 'string',
    // "RecNum": 0,
    // "AttendanceName": data['AttendanceName'],
    // "AttendanceId": data['AttendanceId'],
    // "AttendancePlace": data['AttendancePlace'],
    // "AttendanceTime": data['AttendanceTime'],
    // "Note": data['Note'],
    'timestamp': DateTime.now().millisecondsSinceEpoch,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('getAttendance'),
    'method': 'POST',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}

/**
 *  上传文件
 */
void slk_uploadFile(Map data, Function(String)? cb) {
  LOGI('param $data');

  var loginData = {
    ...data,
  };

  Map<String, dynamic> params = {
    'url': GetBaseUrl('uploadFile'),
    'method': 'POSTFILE',
    'data': loginData,
  };

  //
  httpSend(params, (p0) {
    if (cb != null) {
      cb!(p0);
      cb = null;
    }
  });
}
